home *** CD-ROM | disk | FTP | other *** search
/ Resource for Source: C/C++ / Resource for Source - C-C++.iso / misc_src / cslib16b / demo / address / csaddio.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-01  |  22.5 KB  |  724 lines

  1. /////////////////////////////////////////////////////////
  2. //     Implementation file of database class: NAM_foundation.
  3. //                                                          
  4. //     Source generated by: CSDBGEN version 1.2.b.
  5. //     Date of generation:  Thursday, 2 March 1995.
  6. //     Time of generation:  12:00:12.
  7. //                                                          
  8. //                                                          
  9. //     The next lines represent the database definition     
  10. //     file used as input for CSDBGEN.                      
  11. //                                                          
  12. //                                                          
  13. ////////////// Start of the .def file //////////////////
  14. /*
  15. class: NAM_foundation
  16. record: record
  17. file: csadr.dbf
  18. field: name s 40 T
  19. field: adre s 32
  20. field: city s 23 Y
  21. field: count s 32
  22. field: zip s 9
  23. field: tel s 17
  24. field: update d MDY2
  25. field: birth d DMY4 Y
  26. field: relation s 10 Y
  27. field: info s 70
  28. */
  29. /////////////// End of .def file //////////////////////////////////////////////
  30. /*
  31.  
  32.  
  33.  
  34.                  █████     █                       █        
  35.                 ██   ██   ██                      ██        
  36.                 ███      ████     ███   ██ ███   ████       
  37.                   ███     ██        ██   ███ ██   ██        
  38.                     ███   ██     █████   ██       ██        
  39.                 ██   ██   ██ █  ██  ██   ██       ██ █      
  40.                  █████     ██    ███ ██  ██        ██       
  41.                                                             
  42.                                                             
  43.              ████     ████  ██  ██  ██ ███   █████   ████   
  44.             ██       ██  ██ ██  ██   ███ ██ ██   █  ██  ██  
  45.              ████    ██  ██ ██  ██   ██     ██      ██████  
  46.                 ██   ██  ██ ██  ██   ██     ██   █  ██      
  47.              ████     ████   ███ ██  ██      █████   █████  
  48.                                                             
  49.  
  50.  
  51. */
  52. //////////////////////////////////////////////////////////////////////////////
  53.  
  54. #include "csaddio.h"
  55.  
  56. extern unsigned _stklen=7000;  //A large stack is needed
  57.  
  58.  
  59. ///////////////////////////////// Constructor ////////////////////////////////
  60. NAM_foundation::NAM_foundation(void) 
  61.     is_open=FALSE; 
  62.     current=1; 
  63.     _update.format(MDY2); 
  64.     _birth.format(DMY4); 
  65. }
  66.  
  67. ///////////////////////////////// reindex ////////////////////////////////////
  68. void NAM_foundation::reindex(void) 
  69. {
  70.     U32 l=current;  
  71.     record *rp;  
  72.     in1.empty(); 
  73.     in2.empty(); 
  74.     in3.empty(); 
  75.     in4.empty(); 
  76.     for(current=numrec(); current>0; current--)  
  77.     {                          
  78.        rp=(record *)db.locate_rec(current);  
  79.        tokenize(rp->_name,&NAM_foundation::in1_ins_tok); 
  80.        in2.insert(rp->_city,¤t); 
  81.        in3.insert(&rp->__birth,¤t); 
  82.        in4.insert(rp->_relation,¤t); 
  83.     }                          
  84.     current=l;                 
  85. }
  86.  
  87. /////////////// go_to ////////////////////////////////////////////
  88. void NAM_foundation::go_to(long n) 
  89. {
  90.     if(order()!=UNSORTED) 
  91.     {
  92.       csmess_p(7110,"NAM_foundation"); 
  93.       return; 
  94.     }
  95.     write_rec(); 
  96.     current=max(min(n,db.numrec()),1); 
  97.     read_rec(); 
  98. }
  99.  
  100. /////////////// append blank//////////////////////////////////////
  101. void NAM_foundation::append_blank(void) 
  102. {
  103.        append();
  104.        tokenize(recp->_name,&NAM_foundation::in1_ins_tok); 
  105.        in2.insert(rec._city,¤t); 
  106.        in3.insert(&rec.__birth,¤t); 
  107.        in4.insert(rec._relation,¤t); 
  108. }
  109.  
  110. ///////////////////////////////// append /////////////////////////////////////
  111. // This function doesn't update the indexes, which can save some 
  112. // disk I/O because you are likely to alter the fields 
  113. // immediately after you have appended the record.
  114. // However, if you have an index on a field you don't update, this 
  115. // record will NOT appear in that particular index! 
  116. // The 'append_blank' function does update all indexes, which 
  117. // makes it a safer, but slower option. 
  118. //  
  119. void NAM_foundation::append(void) 
  120. {
  121.     write_rec();
  122.     memset(&rec,0,sizeof(record)); 
  123.     current=db.append_rec(&rec); 
  124.     recp=(record *)db.locate_rec(current); 
  125.     dirty=TRUE;    
  126.     _update.sem_jul(0L);
  127.     _birth.sem_jul(0L);
  128. }
  129.  
  130. ///////////////////////////////// open ///////////////////////////////////////
  131. void NAM_foundation::open(void) 
  132. {
  133.      if(is_open) return; 
  134.      int needs_reindex=FALSE;        
  135.      dirty=FALSE;        
  136.  
  137. #ifdef _Windows
  138.      int fre=300/9; //Use 300 Kb for buffers. You may increase this.
  139. #else
  140.      int fre=(int)(coreleft()-100000L)/9/1024;
  141.      fre=max(fre,0); 
  142. #endif
  143.  
  144.      if(!db.open("csadr.dbf",fre)) 
  145.      {
  146.          csmess_disp("FATAL: Can't open database csadr.dbf.");
  147.          exit(1);
  148.      }
  149.      if(db.lengthrec()!=sizeof(record)) 
  150.      {
  151.          csmess_disp("FATAL: wrong record size.\n\rProbably wrong or old database file.");
  152.          db.close(); 
  153.          exit(1); 
  154.      }
  155.      if(!file_exist("csadr01.idx"))
  156.      { 
  157.        in1.multiple_keys(TRUE);
  158.        in1.define("csadr01.idx",NAME_LENGTH/2,sizeof(long));
  159.        needs_reindex=TRUE; 
  160.      } 
  161.      in1.open("csadr01.idx",fre*2);
  162.   
  163.      if(!file_exist("csadr02.idx"))
  164.      { 
  165.        in2.multiple_keys(TRUE);
  166.        in2.define("csadr02.idx",CITY_LENGTH+1,sizeof(long));
  167.        needs_reindex=TRUE; 
  168.      } 
  169.      in2.open("csadr02.idx",fre*2);
  170.   
  171.      if(!file_exist("csadr03.idx"))
  172.      { 
  173.        in3.multiple_keys(TRUE);
  174.        in3.define("csadr03.idx",sizeof(long),sizeof(long));
  175.        needs_reindex=TRUE; 
  176.      } 
  177.      in3.open("csadr03.idx",fre*2);
  178.   
  179.      if(!file_exist("csadr04.idx"))
  180.      { 
  181.        in4.multiple_keys(TRUE);
  182.        in4.define("csadr04.idx",RELATION_LENGTH+1,sizeof(long));
  183.        needs_reindex=TRUE; 
  184.      } 
  185.      in4.open("csadr04.idx",fre*2);
  186.   
  187.      if(needs_reindex) reindex(); 
  188.      is_open=TRUE; 
  189.      if(numrec()==0) append_blank();
  190.      else            read_rec(); 
  191.   
  192.      order(UNSORTED);  
  193. }
  194.  
  195. ///////////////////////////////// close //////////////////////////////////////
  196. void NAM_foundation::close(void) 
  197. {
  198.      if(!is_open) return; 
  199.      write_rec(); 
  200.      db.close(); 
  201.      in1.close();
  202.      in2.close();
  203.      in3.close();
  204.      in4.close();
  205.      is_open=FALSE; 
  206. }
  207.  
  208. ///////////////////////////////// define /////////////////////////////////////
  209. void NAM_foundation::define(void) 
  210. {
  211.      db.define("csadr.dbf",sizeof(record)); 
  212.      in1.multiple_keys(TRUE);
  213.      in1.define("csadr01.idx",NAME_LENGTH/2,sizeof(long));
  214.      in2.multiple_keys(TRUE);
  215.      in2.define("csadr02.idx",CITY_LENGTH+1,sizeof(long));
  216.      in3.multiple_keys(TRUE);
  217.      in3.define("csadr03.idx",sizeof(long),sizeof(long));
  218.      in4.multiple_keys(TRUE);
  219.      in4.define("csadr04.idx",RELATION_LENGTH+1,sizeof(long));
  220. }
  221.  
  222. ///////////////////////////////// pack ///////////////////////////////////////
  223. void NAM_foundation::pack(void) 
  224. {
  225.      write_rec(); 
  226.      db.pack();
  227.      reindex();
  228.      if(numrec()==0) append_blank();
  229.      top();
  230. }
  231.  
  232. ///////////////////////////////// skip ///////////////////////////////////////
  233. int  NAM_foundation::skip0(int delta) 
  234. {
  235.      long old_current=current; 
  236.      current=max(min(current+delta,db.numrec()),1); 
  237.      return current-old_current; 
  238. }
  239.  
  240. int  NAM_foundation::skip(int delta) 
  241. {
  242.      int rc; 
  243.      write_rec(); 
  244.      rc=(this->*skip_fun)(delta); 
  245.      read_rec(); 
  246.      return rc; 
  247. }
  248.  
  249. ///////////////////////////////// order //////////////////////////////////////
  250. void NAM_foundation::order(int nr) 
  251. {
  252.      switch(nr)
  253.      {
  254.          case 0:        //Unsorted 
  255.                   bof_fun   =&NAM_foundation::bof0;
  256.                   eof_fun   =&NAM_foundation::eof0;
  257.                   skip_fun  =&NAM_foundation::skip0;
  258.                   top_fun   =&NAM_foundation::top0;
  259.                   bottom_fun=&NAM_foundation::bottom0;
  260.                   search_fun=&NAM_foundation::search0;
  261.                   break; 
  262.          case 1:        //Index on field name
  263.                   bof_fun   =&NAM_foundation::bof1;
  264.                   eof_fun   =&NAM_foundation::eof1;
  265.                   skip_fun  =&NAM_foundation::skip1;
  266.                   top_fun   =&NAM_foundation::top1;
  267.                   bottom_fun=&NAM_foundation::bottom1;
  268.                   search_fun=&NAM_foundation::search1;
  269.                   break; 
  270.          case 2:        //Index on field city
  271.                   bof_fun   =&NAM_foundation::bof2;
  272.                   eof_fun   =&NAM_foundation::eof2;
  273.                   skip_fun  =&NAM_foundation::skip2;
  274.                   top_fun   =&NAM_foundation::top2;
  275.                   bottom_fun=&NAM_foundation::bottom2;
  276.                   search_fun=&NAM_foundation::search2;
  277.                   break; 
  278.          case 3:        //Index on field birth
  279.                   bof_fun   =&NAM_foundation::bof3;
  280.                   eof_fun   =&NAM_foundation::eof3;
  281.                   skip_fun  =&NAM_foundation::skip3;
  282.                   top_fun   =&NAM_foundation::top3;
  283.                   bottom_fun=&NAM_foundation::bottom3;
  284.                   search_fun=&NAM_foundation::search3;
  285.                   break; 
  286.          case 4:        //Index on field relation
  287.                   bof_fun   =&NAM_foundation::bof4;
  288.                   eof_fun   =&NAM_foundation::eof4;
  289.                   skip_fun  =&NAM_foundation::skip4;
  290.                   top_fun   =&NAM_foundation::top4;
  291.                   bottom_fun=&NAM_foundation::bottom4;
  292.                   search_fun=&NAM_foundation::search4;
  293.                   break; 
  294.          default: return; // Function called with wrong parameter.
  295.      }
  296.      iOrder=nr;
  297.      top();
  298. }
  299. /////////////////////////////writing record  ///////////////////////////////
  300. void NAM_foundation::write_rec2(void) 
  301. {
  302.     if(strcmp(recp->_name,rec._name)) 
  303.     { 
  304.       tokenize(recp->_name,&NAM_foundation::in1_del_tok); 
  305.       tokenize(rec._name,&NAM_foundation::in1_ins_tok); 
  306.     } 
  307.     if(strcmp(recp->_city,rec._city)) 
  308.     { 
  309.       in2.delet(recp->_city,¤t); 
  310.       in2.insert(rec._city,¤t); 
  311.     } 
  312.     rec.__update=_update.sem_jul(); 
  313.     rec.__birth=_birth.sem_jul(); 
  314.     if(recp->__birth!=rec.__birth) 
  315.     { 
  316.       in3.delet(&recp->__birth,¤t); 
  317.       in3.insert(&rec.__birth,¤t); 
  318.     } 
  319.     if(strcmp(recp->_relation,rec._relation)) 
  320.     { 
  321.       in4.delet(recp->_relation,¤t); 
  322.       in4.insert(rec._relation,¤t); 
  323.     } 
  324.     db.write_rec(current,&rec); 
  325.     dirty=FALSE;   
  326. }
  327.  
  328. ///////////////////////////////// export /////////////////////////////////////
  329. int  NAM_foundation::export(char *s) 
  330. {
  331.      FILE *fo=fopen(s,"w"); 
  332.      if(fo==NULL) return FALSE; 
  333.  
  334.      write_rec();
  335.      fprintf(fo,"class:  NAM_foundation");
  336.      fprintf(fo,"\nrecord: record");
  337.      fprintf(fo,"\nfile:   csadr.dbf");
  338.      fprintf(fo,"\nfield:  name s 40 Y");
  339.      fprintf(fo,"\nfield:  adre s 32  ");
  340.      fprintf(fo,"\nfield:  city s 23 Y");
  341.      fprintf(fo,"\nfield:  count s 32  ");
  342.      fprintf(fo,"\nfield:  zip s 9  ");
  343.      fprintf(fo,"\nfield:  tel s 17  ");
  344.      fprintf(fo,"\nfield:  update d  ");
  345.      fprintf(fo,"\nfield:  birth d Y");
  346.      fprintf(fo,"\nfield:  relation s 10 Y");
  347.      fprintf(fo,"\nfield:  info s 70  ");
  348.  
  349.      if(ferror(fo)) { fclose(fo); return FALSE; } 
  350.  
  351.      record *recp;
  352.      DATE conv;
  353.      conv.format(Y4MD);
  354.      for(long l=numrec();l>0;l--) 
  355.      {
  356.         recp=( record * )db.locate_rec(l);
  357.         fprintf(fo,"\n%c",12);
  358.         fprintf(fo,"\n%s",recp->_name);
  359.         fprintf(fo,"\n%s",recp->_adre);
  360.         fprintf(fo,"\n%s",recp->_city);
  361.         fprintf(fo,"\n%s",recp->_count);
  362.         fprintf(fo,"\n%s",recp->_zip);
  363.         fprintf(fo,"\n%s",recp->_tel);
  364.         conv.sem_jul(recp->__update);
  365.         fprintf(fo,"\n%s",(char *)conv);
  366.         conv.sem_jul(recp->__birth);
  367.         fprintf(fo,"\n%s",(char *)conv);
  368.         fprintf(fo,"\n%s",recp->_relation);
  369.         fprintf(fo,"\n%s",recp->_info);
  370.         fprintf(fo,"\n"); //Additional linefeed, to avoid trouble!
  371.  
  372.         if(ferror(fo)) { fclose(fo); return FALSE; } 
  373.      }
  374.      return !fclose(fo);  
  375. }
  376.  
  377. ///////////////////////////////// import /////////////////////////////////////
  378. int NAM_foundation::import(char *s) 
  379. {   
  380.  
  381.       FILE *fr=fopen(s,"r"); 
  382.       if(fr==NULL) return FALSE;
  383.   
  384.   
  385. #define MAX_NUM_FIELDS  100   //Increase this to allow more fields    
  386. #define MAX_FIELD_LEN   500   //Increase this to allow longer fields  
  387.  
  388.       int *finu;
  389.       finu=(int *)malloc(MAX_NUM_FIELDS*sizeof(int));
  390.       if(finu==NULL) { fclose(fr); return FALSE; }   
  391.  
  392.       char *fibu;    
  393.       fibu=(char *)malloc(MAX_FIELD_LEN);
  394.       if(fibu==NULL) { fclose(fr); free(finu); return FALSE; } 
  395.       *fibu=0;  
  396.  
  397.       char *fipo=fibu+strlen("field:");  
  398.       char *cp; 
  399.       int  ifieldnr=0;    
  400.       int  ofieldnr; 
  401.       DATE conv;
  402.       conv.format(Y4MD);
  403.  
  404.       memset(finu,0,MAX_NUM_FIELDS*sizeof(int));
  405.  
  406.       fgets(fibu,MAX_FIELD_LEN,fr); 
  407.       while(!strchr(fibu,12))  
  408.       {    
  409.         strlwr(fibu);
  410.         notabs(fibu);
  411.         trim_string(fibu);
  412.         if(strstr(fibu,"field:"))   
  413.         {  
  414.            ifieldnr++;  
  415.            trim_string(fipo);    
  416.            if((cp=strchr(fipo,' '))!=NULL) *cp=0;
  417.            if     (!strcmp(fipo,"name"))    ofieldnr=1;
  418.            else if(!strcmp(fipo,"adre"))    ofieldnr=2;
  419.            else if(!strcmp(fipo,"city"))    ofieldnr=3;
  420.            else if(!strcmp(fipo,"count"))    ofieldnr=4;
  421.            else if(!strcmp(fipo,"zip"))    ofieldnr=5;
  422.            else if(!strcmp(fipo,"tel"))    ofieldnr=6;
  423.            else if(!strcmp(fipo,"update"))    ofieldnr=7;
  424.            else if(!strcmp(fipo,"birth"))    ofieldnr=8;
  425.            else if(!strcmp(fipo,"relation"))    ofieldnr=9;
  426.            else if(!strcmp(fipo,"info"))    ofieldnr=10;
  427.            else ofieldnr=0; 
  428.            finu[ifieldnr]=ofieldnr; 
  429.         }  
  430.         fgets(fibu,MAX_FIELD_LEN,fr);    
  431.       }    
  432.  
  433.  
  434.  
  435.       for(;;)   
  436.       {    
  437.         if(!strchr(fibu,12))   
  438.         {  
  439.            ifieldnr++; 
  440.            if(ifieldnr<MAX_NUM_FIELDS) 
  441.              switch(finu[ifieldnr])   
  442.              {  
  443.                 case 0:  break;
  444.                 case 1:
  445.                          fibu[NAME_LENGTH]=0;
  446.                          name(fibu);
  447.                          break;
  448.                 case 2:
  449.                          fibu[ADRE_LENGTH]=0;
  450.                          adre(fibu);
  451.                          break;
  452.                 case 3:
  453.                          fibu[CITY_LENGTH]=0;
  454.                          city(fibu);
  455.                          break;
  456.                 case 4:
  457.                          fibu[COUNT_LENGTH]=0;
  458.                          count(fibu);
  459.                          break;
  460.                 case 5:
  461.                          fibu[ZIP_LENGTH]=0;
  462.                          zip(fibu);
  463.                          break;
  464.                 case 6:
  465.                          fibu[TEL_LENGTH]=0;
  466.                          tel(fibu);
  467.                          break;
  468.                 case 7:
  469.                          conv=fibu;
  470.                          _update.sem_jul(conv.sem_jul());
  471.                          break;
  472.                 case 8:
  473.                          conv=fibu;
  474.                          _birth.sem_jul(conv.sem_jul());
  475.                          break;
  476.                 case 9:
  477.                          fibu[RELATION_LENGTH]=0;
  478.                          relation(fibu);
  479.                          break;
  480.                 case 10:
  481.                          fibu[INFO_LENGTH]=0;
  482.                          info(fibu);
  483.                          break;
  484.              }  
  485.         }  
  486.         else    
  487.         {  
  488.            ifieldnr=0; 
  489.            append_blank();
  490.         }  
  491.         if(feof(fr)) break;    
  492.         fgets(fibu,MAX_FIELD_LEN,fr);    
  493.         cp=fibu+(max(1,strlen(fibu))-1); 
  494.         if(*cp=='\n') *cp=0;  //removing the line feed 
  495.       }    
  496.  
  497.  
  498.       fclose(fr); 
  499.       free(fibu); 
  500.       free(finu); 
  501.  
  502. #undef MAX_NUM_FIELDS
  503. #undef MAX_FIELD_LEN 
  504.  
  505.  return TRUE; 
  506. }
  507.  
  508. ///////////////////////////////// export to dBASE compatible file. ///////////
  509. int NAM_foundation::to_DBASE(char *s) 
  510. {   
  511.  
  512.       char bufje[12];
  513.       if(!is_open) return FALSE;
  514.  
  515.       write_rec(); 
  516.       FILE *fo=fopen(s,"wb"); 
  517.       if(fo==NULL) return FALSE;
  518.   
  519.       int i;
  520.   
  521.       DATE d_upda;
  522.       d_upda.sem_jul(db.sj_updated());
  523.       fputc(03,fo);  
  524.       
  525.       fputc(d_upda.year()%100,fo);  
  526.       fputc(d_upda.month(),fo);  
  527.       fputc(d_upda.day(),fo);  
  528.  
  529.       long nr_record=numrec(); 
  530.       fwrite(&nr_record,sizeof(long),1,fo); 
  531.       putw(354,fo);        //Header length 
  532.       putw(250,fo);        //Length of data record 
  533.       for(i=0;i<20;i++) fputc(0,fo); // 20 dummy bytes 
  534.  
  535.  
  536. // Writing definition of field name to dbase file header.
  537.       memset(bufje,0,11);
  538.       strcpy(bufje,"NAME");
  539.       fwrite(bufje,11,1,fo);
  540.       fputc('C',fo); 
  541.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  542.       fputc(40,fo); 
  543.       fputc(0,fo); 
  544.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  545.  
  546. // Writing definition of field adre to dbase file header.
  547.       memset(bufje,0,11);
  548.       strcpy(bufje,"ADRE");
  549.       fwrite(bufje,11,1,fo);
  550.       fputc('C',fo); 
  551.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  552.       fputc(32,fo); 
  553.       fputc(0,fo); 
  554.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  555.  
  556. // Writing definition of field city to dbase file header.
  557.       memset(bufje,0,11);
  558.       strcpy(bufje,"CITY");
  559.       fwrite(bufje,11,1,fo);
  560.       fputc('C',fo); 
  561.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  562.       fputc(23,fo); 
  563.       fputc(0,fo); 
  564.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  565.  
  566. // Writing definition of field count to dbase file header.
  567.       memset(bufje,0,11);
  568.       strcpy(bufje,"COUNT");
  569.       fwrite(bufje,11,1,fo);
  570.       fputc('C',fo); 
  571.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  572.       fputc(32,fo); 
  573.       fputc(0,fo); 
  574.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  575.  
  576. // Writing definition of field zip to dbase file header.
  577.       memset(bufje,0,11);
  578.       strcpy(bufje,"ZIP");
  579.       fwrite(bufje,11,1,fo);
  580.       fputc('C',fo); 
  581.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  582.       fputc(9,fo); 
  583.       fputc(0,fo); 
  584.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  585.  
  586. // Writing definition of field tel to dbase file header.
  587.       memset(bufje,0,11);
  588.       strcpy(bufje,"TEL");
  589.       fwrite(bufje,11,1,fo);
  590.       fputc('C',fo); 
  591.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  592.       fputc(17,fo); 
  593.       fputc(0,fo); 
  594.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  595.  
  596. // Writing definition of field update to dbase file header.
  597.       memset(bufje,0,11);
  598.       strcpy(bufje,"UPDATE");
  599.       fwrite(bufje,11,1,fo);
  600.       fputc('D',fo); 
  601.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  602.       fputc(8,fo); 
  603.       fputc(0,fo); 
  604.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  605.  
  606. // Writing definition of field birth to dbase file header.
  607.       memset(bufje,0,11);
  608.       strcpy(bufje,"BIRTH");
  609.       fwrite(bufje,11,1,fo);
  610.       fputc('D',fo); 
  611.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  612.       fputc(8,fo); 
  613.       fputc(0,fo); 
  614.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  615.  
  616. // Writing definition of field relation to dbase file header.
  617.       memset(bufje,0,11);
  618.       strcpy(bufje,"RELATION");
  619.       fwrite(bufje,11,1,fo);
  620.       fputc('C',fo); 
  621.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  622.       fputc(10,fo); 
  623.       fputc(0,fo); 
  624.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  625.  
  626. // Writing definition of field info to dbase file header.
  627.       memset(bufje,0,11);
  628.       strcpy(bufje,"INFO");
  629.       fwrite(bufje,11,1,fo);
  630.       fputc('C',fo); 
  631.       for(i=0;i<4;i++) fputc(0,fo); // 4 dummy bytes 
  632.       fputc(70,fo); 
  633.       fputc(0,fo); 
  634.       for(i=0;i<14;i++) fputc(0,fo); // 14 dummy bytes 
  635.  
  636.  
  637.       fputc(13,fo);  //Field terminator 
  638.       fputc(0,fo); 
  639.  
  640. // By now we have written the definition of the 
  641. // record structure to the file header. 
  642. // From here on we will export the records. 
  643.  
  644.      record *recp;
  645.      for(long l=numrec();l>0;l--) 
  646.      {
  647.  
  648.         if(ferror(fo)) { fclose(fo); return FALSE; } 
  649.         recp=(record *)db.locate_rec(l);
  650.  
  651.         if(db.is_delet(l)) fputc(42,fo); 
  652.         else               fputc(32,fo); 
  653.  
  654. /////////////////////// writing field name /////////////
  655.         fprintf(fo,"%-40s",recp->_name);
  656. /////////////////////// writing field adre /////////////
  657.         fprintf(fo,"%-32s",recp->_adre);
  658. /////////////////////// writing field city /////////////
  659.         fprintf(fo,"%-23s",recp->_city);
  660. /////////////////////// writing field count /////////////
  661.         fprintf(fo,"%-32s",recp->_count);
  662. /////////////////////// writing field zip /////////////
  663.         fprintf(fo,"%-9s",recp->_zip);
  664. /////////////////////// writing field tel /////////////
  665.         fprintf(fo,"%-17s",recp->_tel);
  666. /////////////////////// writing field update /////////////
  667.         if(recp->__update)
  668.         { 
  669.           d_upda.sem_jul(recp->__update);
  670.           fprintf(fo,"%4d",d_upda.year4());
  671.           fprintf(fo,"%02d",d_upda.month());
  672.           fprintf(fo,"%02d",d_upda.day());
  673.         } 
  674.         else 
  675.         { 
  676.           fprintf(fo,"        "); 
  677.         } 
  678. /////////////////////// writing field birth /////////////
  679.         if(recp->__birth)
  680.         { 
  681.           d_upda.sem_jul(recp->__birth);
  682.           fprintf(fo,"%4d",d_upda.year4());
  683.           fprintf(fo,"%02d",d_upda.month());
  684.           fprintf(fo,"%02d",d_upda.day());
  685.         } 
  686.         else 
  687.         { 
  688.           fprintf(fo,"        "); 
  689.         } 
  690. /////////////////////// writing field relation /////////////
  691.         fprintf(fo,"%-10s",recp->_relation);
  692. /////////////////////// writing field info /////////////
  693.         fprintf(fo,"%-70s",recp->_info);
  694.      }
  695.      fputc(26,fo);  //End of File 
  696.      fclose(fo); 
  697.  
  698.  return TRUE; 
  699. }
  700.  
  701. ///////////////////////////////// tokenize field ///////////////////////
  702. void NAM_foundation::tokenize(char *s,void(NAM_foundation::*fun)(void *))
  703. {
  704.  
  705.      char delim[]="\t,()- "; //Token delimiters
  706.      const min_len=4;  //Minimum length for a token to be indexed.
  707.      char *p,*q=s;
  708.      char c;
  709.      int  insert=FALSE;
  710.  
  711.      p=strpbrk(q,delim);
  712.      while(p)
  713.      {
  714.         c=*p; *p=0;
  715.         if(strlen(q)>=min_len) { (this->*fun)(q); insert=TRUE; }
  716.         *p=c;
  717.         do{ p=strpbrk(q=p+1,delim); }while(q==p);
  718.      }
  719.  
  720.      if(strlen(q)>=min_len) { (this->*fun)(q); insert=TRUE; }
  721.      if(!insert) (this->*fun)(s);
  722.  
  723. }